package com.ocom.payhandle.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.human.EntityPersonnelPalmprint;
import com.ocom.payhandle.vo.PersonnelInfoVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IDaoPersonnelInfoVo extends BaseMapper<PersonnelInfoVo> {

    @Select({"<script>",
            "select distinct  c.card_no  from   xf_account_info x \n" +
                    "inner join card_info c on x.com_id=c.com_id and x.account_no=c.account_no and  c.card_state &lt;&gt; 2\n" +
                    " where \n" +
                    " <when test=\"courseIds!=null and courseIds.size() &gt; 0 \" > "+
                    " x.p_id in " +
                    " <foreach collection='courseIds' item='pId' open='(' separator=',' close=')'> "+
                    " #{pId}  "+
                    " </foreach> "+
                    "</when>",
            "</script>"})
    List<PersonnelInfoVo> selectCard(@Param("courseIds") List<Integer> courseIds);

    @Select({"<script>",
            "select  p.p_id ,p.p_name,c.card_no,x.acc_type_id,c.card_state from  personnel_info p \n" +
                    "inner join xf_account_info x on p.p_id=x.p_id\n " +
                    "left join card_info c on x.com_id=c.com_id and x.account_no=c.account_no and  c.card_state &lt;&gt; 2 \n" +
                    " where \n" +
                    " <when test=\"courseIds!=null and courseIds.size() &gt; 0 \" > "+
                    "  x.p_id in " +
                    " <foreach collection='courseIds' item='pId' open='(' separator=',' close=')'> "+
                    " #{pId}  "+
                    " </foreach> "+
                    "</when>",
            "</script>"})
    List<PersonnelInfoVo> selectPersonnelInfoCard(@Param("courseIds") List<Integer> courseIds);

    @Select({"<script>",
            "select  p.p_id ,p.p_name,p.p_photo_url2,p.p_photo_url,x.acc_type_id" +
//                    ",c.card_no,f.feature,f.feature2,c.card_state " +
                    " from  personnel_info p \n" +
                    " inner join xf_account_info x ON p.com_id = x.com_id and p.p_id=x.p_id\n" +
//                    "left join card_info c on x.com_id=c.com_id and x.account_no=c.account_no and  c.card_state &lt;&gt; 2\n" +
//                    "LEFT JOIN personnel_feature f ON p.com_id = f.com_id AND p.p_id = f.p_id AND f.version = #{version}" +
                    " where \n" +
                    " p.com_id = #{comId}\n" +
                    " <when test=\"courseIds!=null and courseIds.size() &gt; 0 \" > "+
                    " and p.p_id in  " +
                    " <foreach collection='courseIds' item='pId' open='(' separator=',' close=')'> "+
                    " #{pId}  "+
                    " </foreach> "+
                    "</when>",
            "</script>"})
    List<PersonnelInfoVo> selectPersonnelInfoUrl(@Param("comId") long comId,@Param("courseIds") List<Integer> courseIds, @Param("version") String version);

    @Select({"<script>",
            "select  " +
                    " c.p_id, c.card_no, f.feature, f.feature2, c.card_state " +
                    " from  card_info c \n" +
                    " LEFT JOIN personnel_feature f ON c.com_id = f.com_id AND c.p_id = f.p_id AND f.version = #{version}" +
                    " where \n" +
                    " c.com_id = #{comId}\n" +
                    " AND c.card_state &lt;&gt; 2" +
                    " <when test=\"courseIds!=null and courseIds.size() &gt; 0 \" > "+
                    " and c.p_id in  " +
                    " <foreach collection='courseIds' item='pId' open='(' separator=',' close=')'> "+
                    " #{pId}  "+
                    " </foreach> "+
                    "</when>",
            "</script>"})
    List<PersonnelInfoVo> selectPersonnelInfoUrl2(@Param("comId") long comId, @Param("courseIds") List<Integer> courseIds, @Param("version") String version);

    @Select({"<script>",
            "select  p.* from  personnel_palmprint p " +
                    " where \n" +
                    " p.com_id = #{comId}\n" +
                    " <when test=\"pIds!=null and pIds.size() &gt; 0 \" > "+
                    "  and p.p_id in  " +
                    " <foreach collection='pIds' item='pId' open='(' separator=',' close=')'> "+
                    " #{pId}  "+
                    " </foreach> "+
                    "</when>",
            "</script>"})
    List<EntityPersonnelPalmprint> getPalmByPIds(@Param("comId") long comId, @Param("pIds") List<Integer> pIds);
}
